<?php
/**
 * Data model
 *
 * @category  DataModel
 * @package   DataModel
 * @author    DataModel Generator v1.0
 * @version   $Revision: 127 $
 */
/**
 * Data model for table "pfolder"
 *
 * @category  DataModel
 * @package   DataModel
 * @author    DataModel Generator v1.0
 * @version   $Revision: 127 $
 */

 /*
class Pfolder extends BasePfolder
{
    public function findByWords(array $words)
    {
        $q = ORMQuery::selectBuilder()
            ->from('Pfolder pf');
        foreach($words as $word) {
            $word = trim($word);
			$q ->orWhere('pf.name LIKE ?','%' . $word . '%');
			$q ->orWhere('pf.path LIKE ?','%' . $word . '%');
        }
        return $q->fetchAll('Pfolder');
    }
    
	public static function getFolder($path)
	{
		$folder = new Pfolder();
		//print $path.' * ';		
		$name = end(explode( '/', $path ));
		//print  $name.' * ';
		return $folder->getByParams(array('name' => $name));		
		//print $found->id;exit;
	}
    
	public function getLocation()
    {
		$all = self::getAll();
		$folders = array();
		foreach($all as &$item) {
			$folders[$item->id] = $item;
		}
		$res = self::getLoc($this->parent_id, $folders);
		$res[] = $this->name;
		return '/' . implode($res,'/') . '/';
    }

	protected static function getLoc($folderId, &$folders)
    {		
		$folder = $folders[$folderId];
		$res = array($folder->name);
		if($folder->parent_id) {
			$res = array_merge(self::getLoc($folder->parent_id, $folders),$res);
		}
		return $res;
    }	
	
    public function getById($id)
    {
        return parent::getById($id, __CLASS__);
    }
    
    public function getByParams( $params, $type = self::ONE_RECORD, $limit = null )
    {
        return parent::getByParams( $params, $type, $limit, __CLASS__);
    }
    
    public function getAll( $limit = null )
    {
        return parent::getAll( $limit, __CLASS__ );
    }

    public static function saveIfNotExists($params = null)
    {
        return parent::saveIfNotExists($params, __CLASS__);
    }

    public static function deleteByProject(Project $project) 
    {

        
        $q = ORMQuery::selectBuilder()
            ->select('dt.id')
            ->from('Doctype dt')
            ->leftJoin( 'Phpclass pcref' , array( 'doctype_id','dt.id' ))
            ->leftJoin( 'Pfile fileref' , array( 'id','pcref.file_id' ))
            ->leftJoin( 'Pfolder foldref' , array( 'id','fileref.folder_id' ))
            ->andWhere( 'foldref.project_id = ?', $project->id );        
        $res = $q->fetchAll();
        $doctypes = array();
        foreach($res as &$doctype) {
            $doctypes[] = $doctype->id;
        }
        if(count($doctypes)>0) {
            $q = ORMQuery::deleteBuilder()
                ->from('Doctype')
                ->where('id IN ('.implode(',',$doctypes).')');
            $q->exec();
        }
        //print_r($doctypes);exit;
    
        $q = ORMQuery::deleteBuilder()
            ->from(__CLASS__)
            ->where('project_id = ?',$project->id);
        $q->exec();
        //print $project->id .' / '. $q;
        //exit;
    }
}*/
